import java.io.*;
import java.util.Objects;

public class Task {
    public static void main(String[] args) {
        final String filename = "lesson9/task15/resource/itheima.txt";
        run(filename);
    }

    public static void run(String filename) {
        final File file = new File(filename);
        if (!file.getParentFile().exists()) {
            file.getParentFile().mkdirs();
        }
        
        try (
                // 1、创建一个文件字节输出流
                OutputStream os = new FileOutputStream(file);
                // 2、把原始的字节输出流，按照指定的字符集编码转换成字符输出转换流。
                Writer osw = new OutputStreamWriter(os, "GBK");
                // 3、把字符输出流包装成缓冲字符输出流
                BufferedWriter bw = new BufferedWriter(osw);
        ){
            bw.write("a宫廷玉液酒");
            bw.newLine();
            bw.write("b一百八一杯");
            bw.newLine();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}